//
//  Vector_disordered.swift
//  SwiftyDSA
//
//  Created by Archer on 2018/8/7.
//  Copyright © 2018年 Archer. All rights reserved.
//

import Foundation

extension Vector where Element: Comparable {
    /// 统计向量中的逆序对对数
    /// 如果向量是有序的 当且仅当disordered() == 0
    public func disordered() -> Int {
        var count = 0
        for i in 1..<endIndex {
            count += (_storage[i - 1] > _storage[i]).toInt()
        }
        return count
    }
}
